pub lto: bool,
pub codegen_units: Option<u32>, // None = use rustc default
pub debuginfo: bool,
- pub ndebug: bool,
+ pub debug_assertions: bool,
pub rpath: bool,
pub test: bool,
pub doc: bool,
pub fn default_dev() -> Profile {
Profile {
debuginfo: true,
+ debug_assertions: true,
..Profile::default()
}
}
Profile {
opt_level: 3,
debuginfo: false,
- ndebug: true,
..Profile::default()
}
}
lto: false,
codegen_units: None,
debuginfo: false,
- ndebug: false,
+ debug_assertions: false,
rpath: false,
test: false,
doc: false,
profile: &Profile,
crate_types: &[&str]) {
let Profile {
- opt_level, lto, codegen_units, debuginfo, ndebug, rpath, test,
+ opt_level, lto, codegen_units, debuginfo, debug_assertions, rpath, test,
doc: _doc,
} = *profile;
cmd.arg("-g");
}
- if ndebug {
- cmd.args(&["--cfg", "ndebug"]);
+ if debug_assertions && opt_level > 0 {
+ cmd.args(&["-C", "debug-assertions=on"]);
+ } else if !debug_assertions && opt_level == 0 {
+ cmd.args(&["-C", "debug-assertions=off"]);
}
if test && target.harness() {
lto: Option<bool>,
codegen_units: Option<u32>,
debug: Option<bool>,
+ debug_assertions: Option<bool>,
rpath: Option<bool>,
}
fn merge(profile: Profile, toml: Option<&TomlProfile>) -> Profile {
let &TomlProfile {
- opt_level, lto, codegen_units, debug, rpath
+ opt_level, lto, codegen_units, debug, debug_assertions, rpath
} = match toml {
Some(toml) => toml,
None => return profile,
lto: lto.unwrap_or(profile.lto),
codegen_units: codegen_units,
debuginfo: debug.unwrap_or(profile.debuginfo),
- ndebug: !debug.unwrap_or(!profile.ndebug),
+ debug_assertions: debug_assertions.unwrap_or(profile.debug_assertions),
rpath: rpath.unwrap_or(profile.rpath),
test: profile.test,
doc: profile.doc,
debug = true # Controls whether the compiler passes -g or `--cfg ndebug`
rpath = false # Controls whether the compiler passes `-C rpath`
lto = false # Controls `-C lto` for binaries and staticlibs
+debug-assertions = true # Controls whether debug assertions are enabled
# The release profile, used for `cargo build --release`
[profile.release]
debug = false
rpath = false
lto = false
+debug-assertions = false
# The testing profile, used for `cargo test`
[profile.test]
debug = true
rpath = false
lto = false
+debug-assertions = true
# The benchmarking profile, used for `cargo bench`
[profile.bench]
debug = false
rpath = false
lto = false
+debug-assertions = false
# The documentation profile, used for `cargo doc`
[profile.doc]
debug = true
rpath = false
lto = false
+debug-assertions = true
```
# The `[features]` Section
compiling = COMPILING, running = RUNNING,
dir = p.url()).as_slice()));
- assert_that(p.cargo_process("bench").arg("foo"),
+ assert_that(p.cargo("bench").arg("foo"),
execs().with_status(0)
- .with_stdout(format!("\
-{compiling} foo v0.0.1 ({dir})
+ .with_stdout(&format!("\
{running} target[..]release[..]foo-[..]
running 1 test
test result: ok. 0 passed; 0 failed; 0 ignored; 1 measured
-",
- compiling = COMPILING, running = RUNNING,
- dir = p.url()).as_slice()));
+", running = RUNNING)));
});
// Regression test for running cargo-bench twice with
{running} `rustc src[..]main.rs --crate-name test --crate-type bin \
-C opt-level=3 \
-C lto \
- --cfg ndebug \
--out-dir {dir}[..]target[..]release \
--emit=dep-info,link \
-L dependency={dir}[..]target[..]release \
{compiling} test v0.0.0 ({url})
{running} `rustc src[..]lib.rs --crate-name test --crate-type lib \
-C opt-level=3 \
- --cfg ndebug \
-C metadata=[..] \
-C extra-filename=-[..] \
--out-dir {dir}[..]target[..]release \
{running} `rustc foo[..]src[..]lib.rs --crate-name foo \
--crate-type dylib --crate-type rlib -C prefer-dynamic \
-C opt-level=3 \
- --cfg ndebug \
-C metadata=[..] \
-C extra-filename=-[..] \
--out-dir {dir}[..]target[..]release[..]deps \
{compiling} test v0.0.0 ({url})
{running} `rustc src[..]lib.rs --crate-name test --crate-type lib \
-C opt-level=3 \
- --cfg ndebug \
-C metadata=[..] \
-C extra-filename=-[..] \
--out-dir {dir}[..]target[..]release \
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", r#"
fn main() {
- if cfg!(ndebug) {
- println!("fast")
- } else {
+ if cfg!(debug_assertions) {
println!("slow")
+ } else {
+ println!("fast")
}
}
"#);
.file("Cargo.toml", &basic_bin_manifest("foo"))
.file("src/foo.rs", r#"
fn main() {
- if cfg!(ndebug) {
- println!("fast")
- } else {
+ if cfg!(debug_assertions) {
println!("slow")
+ } else {
+ println!("fast")
}
}
"#);
{compiling} test v0.0.0 ({url})
{running} `rustc src{sep}lib.rs --crate-name test --crate-type lib \
-C opt-level=1 \
- --cfg ndebug \
+ -C debug-assertions=on \
-C metadata=[..] \
-C extra-filename=-[..] \
-C rpath \
extern crate bar;
fn main() {
- if cfg!(ndebug) {
- println!("fast1")
- } else {
+ if cfg!(debug_assertions) {
println!("slow1")
+ } else {
+ println!("fast1")
}
bar::baz();
}
"#)
.file("bar/src/bar.rs", r#"
pub fn baz() {
- if cfg!(ndebug) {
- println!("fast2")
- } else {
+ if cfg!(debug_assertions) {
println!("slow2")
+ } else {
+ println!("fast2")
}
}
"#);
{compiling} bar v0.0.1 ({url})
{running} `rustc bar{sep}src{sep}bar.rs --crate-name bar --crate-type lib \
-C opt-level=3 \
- --cfg ndebug \
-C metadata=[..] \
-C extra-filename=[..] \
--out-dir {dir}{sep}target{sep}release{sep}deps \
{compiling} foo v0.0.1 ({url})
{running} `rustc examples{sep}a.rs --crate-name a --crate-type bin \
-C opt-level=3 \
- --cfg ndebug \
--out-dir {dir}{sep}target{sep}release{sep}examples \
--emit=dep-info,link \
-L dependency={dir}{sep}target{sep}release \
authors = []
"#)
.file("src/main.rs", r#"
- fn main() { if !cfg!(ndebug) { panic!() } }
+ fn main() { if cfg!(debug_assertions) { panic!() } }
"#);
assert_that(p.cargo_process("run").arg("--release"),
assert_that(p.process(&p.bin("examples/foo")),
execs().with_status(0).with_stdout("example\n"));
- assert_that(p.cargo_process("run"),
+ assert_that(p.cargo("run"),
execs().with_status(0)
.with_stdout(format!("\
{compiling} foo v0.0.1 ([..])